package es.cazadoresmadridejos.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cascade;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import es.cazadoresmadridejos.util.constants.Constants;

@Entity(name="Partner")
@Table(name="usuario")
public class Partner extends BaseEntity{

	public enum Role {
		JUNTA, ADMINISTRADOR,CAZADOR;
	}
	
	public enum HunterType {
		escopetero, escopetero_jubilado,galguero, galguero_jubilado, solo_zorzales
	}
	
	public enum Sex{
		HOMBRE, MUJER;
		
		public String toString() {
			return this.name();
		};
	}
	
	private static final long serialVersionUID = -5938083749452770325L;
	private String userid;
	private String password;
	private String name;
	private String lastName;
	private Date birthDate;
	private String nationalIdentityNumber;
	private Sex sex;
	//datos de contacto
	private String email;
	private String phone;
	private String mobile;
	private City city;
	private Integer postalCode;
	private String street;
	private Integer number;
	private String flat;
	private String door;
	//como socio
	private Boolean hasDeer;
	private Boolean hasBigGame;
	private Boolean hasMale;
	private Boolean onlyManteinance;
	private Integer initYear;
	private HunterType hunterType;
	//Configuración
	private Integer active;
	private Boolean mails;
	private Role role;
	private Integer newPhotos;
	private Integer newItems;
	private Integer newAdviceds;
	private Reason selectedReason;
	private Partner partner;
	private Integer bigGameOrder;
	private Integer deerOrder;
	private Integer partnerNumber;
	private String image;
	private Group group;
	//transient
	private CommonsMultipartFile  file;
	
	
	@Column(name="usuario")
	public String getUserid() {
		return userid;
	}
	public void setUserid(String userid) {
		this.userid = userid;
	}
	@Column(name="password")
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	@Column(name="nombre")
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(name="apellidos")
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	@Column(name="dni")
	public String getNationalIdentityNumber() {
		return nationalIdentityNumber;
	}
	public void setNationalIdentityNumber(String nationalIdentityNumber) {
		this.nationalIdentityNumber = nationalIdentityNumber;
	}
	@Column(name="fecha_nacimiento")
	public Date getBirthDate() {
		return birthDate;
	}
	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}
	@Column(name="email")
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	@Column(name="telefono")
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	@Column(name="movil")
	public String getMobile() {
		return mobile;
	}
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	@Column(name="codigo_postal")
	public Integer getPostalCode() {
		return postalCode;
	}
	public void setPostalCode(Integer postalCode) {
		this.postalCode = postalCode;
	}
	@Column(name="calle")
	public String getStreet() {
		return street;
	}
	public void setStreet(String street) {
		this.street = street;
	}
	@Column(name="numero")
	public Integer getNumber() {
		return number;
	}
	public void setNumber(Integer number) {
		this.number = number;
	}
	@Column(name="piso")
	public String getFlat() {
		return flat;
	}
	public void setFlat(String flat) {
		this.flat = flat;
	}
	@Column(name="puerta")
	public String getDoor() {
		return door;
	}
	public void setDoor(String door) {
		this.door = door;
	}
	@Column(name="asiste_corzo")
	public Boolean getHasDeer() {
		return hasDeer;
	}
	public void setHasDeer(Boolean hasDeer) {
		this.hasDeer = hasDeer;
	}
	@Column(name="solo_mantenimiento")
	public Boolean getOnlyManteinance() {
		return onlyManteinance;
	}
	public void setOnlyManteinance(Boolean onlyManteinance) {
		this.onlyManteinance = onlyManteinance;
	}
	@Column(name="asiste_monterias")
	public Boolean getHasBigGame() {
		return hasBigGame;
	}
	public void setHasBigGame(Boolean hasBigGame) {
		this.hasBigGame = hasBigGame;
	}
	
	@Column(name="asiste_macho_perdiz")
	public Boolean getHasMale() {
		return hasMale;
	}
	public void setHasMale(Boolean hasMale) {
		this.hasMale = hasMale;
	}
	
	
	@Column(name="activo",nullable=false)
	public Integer getActive() {
		return active;
	}
	public void setActive(Integer active) {
		this.active = active;
	}
	
	@Column(name="ano_inicio")
	public Integer getInitYear() {
		return initYear;
	}
	public void setInitYear(Integer initYear) {
		this.initYear = initYear;
	}
	@Column(name="recibe_mail")
	public Boolean getMails() {
		return mails;
	}
	public void setMails(Boolean mails) {
		this.mails = mails;
	}
	@Column(name="fotos_nuevas")
	public Integer getNewPhotos() {
		return newPhotos;
	}
	public void setNewPhotos(Integer newPhotos) {
		this.newPhotos = newPhotos;
	}
	@Column(name="articulos_nuevos")
	public Integer getNewItems() {
		return newItems;
	}
	public void setNewItems(Integer newItems) {
		this.newItems = newItems;
	}
	@Column(name="avisos_nuevos")
	public Integer getNewAdviceds() {
		return newAdviceds;
	}
	public void setNewAdviceds(Integer newAdviceds) {
		this.newAdviceds = newAdviceds;
	}
	
	@Enumerated(EnumType.STRING)
	@Column(name="rol")	
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	@Enumerated(EnumType.STRING)
	@Column(name="tipo")	
	public HunterType getHunterType() {
		return hunterType;
	}
	public void setHunterType(HunterType hunterType) {
		this.hunterType = hunterType;
	}
	
	@ManyToOne
	@JoinColumn(name="ciudad")
	public City getCity() {
		return city;
	}
	public void setCity(City city) {
		this.city = city;
	}

	@Enumerated(EnumType.STRING)
	@Column(name="sexo")
	public Sex getSex() {
		return sex;
	}
	public void setSex(Sex sex) {
		this.sex = sex;
	}
	public void init() {
		setCity(new City());
		getCity().setProvince(new Province());
		getCity().getProvince().setId(1L);
	}
	public void initValues() {
		if(newAdviceds == null){
			newAdviceds = 0;
		}
		if(newItems == null){
			newItems = 0;
		}
		if(newPhotos == null){
			newPhotos = 0;
		}
	}
	
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="temporada_seleccionada")
	public Reason getSelectedReason() {
		return selectedReason;
	}
	public void setSelectedReason(Reason selectedReason) {
		this.selectedReason = selectedReason;
	}
	
	@OneToOne(optional=true,fetch=FetchType.EAGER)
	@Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
	@JoinColumn(name="partner")
	public Partner getPartner() {
		return partner;
	}
	public void setPartner(Partner partner) {
		this.partner = partner;
	}
	
	
	@Transient
	public CommonsMultipartFile getFile() {
		return file;
	}
	public void setFile(CommonsMultipartFile file) {
		this.file = file;
	}
	
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}
		
	@Transient
	public String getStringBirthDay(){
		if(this.birthDate != null){
			return Constants.sdf.format(this.birthDate);
		}
		return "";
	}
	@Column(name="orden_monteria")
	public Integer getBigGameOrder() {
		return bigGameOrder;
	}
	public void setBigGameOrder(Integer bigGameOrder) {
		this.bigGameOrder = bigGameOrder;
	}
	@Column(name="orden_corzo")
	public Integer getDeerOrder() {
		return deerOrder;
	}
	public void setDeerOrder(Integer deerOrder) {
		this.deerOrder = deerOrder;
	}
	
	@Override
	public String toString() {
		String name = this.getName() == null?"":this.getName();
		String lastName = this.getLastName() == null?"":this.getLastName();
		String id = this.getId() == null?"[No id]": "[id: " + this.getId() + "] ";
		return id + ": " + name + "  " + lastName;
	}
	
	@Column(name="numero_socio")
	public Integer getPartnerNumber() {
		return partnerNumber;
	}
	public void setPartnerNumber(Integer partnerNumber) {
		this.partnerNumber = partnerNumber;
	}
	@OneToOne(optional=true,fetch=FetchType.EAGER)
	@Cascade(value=org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
	@JoinColumn(name="grupo")
	public Group getGroup() {
		return group;
	}
	public void setGroup(Group group) {
		this.group = group;
	}

}